<template>
  <div>
    <el-button type="primary" @click="toruku">添加</el-button>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          fixed
          prop="goodsNo"
          label="批次号"
          width="150">
      </el-table-column>
      <el-table-column
          prop="wname"
          label="仓库"
          width="120">
      </el-table-column>
      <el-table-column
          prop="status"
          label="出库类型"
          width="120">
        <template v-slot="s">
          <el-tag v-if="s.row.status==1">入库</el-tag>
          <el-tag v-if="s.row.status==2">出库</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="comment"
          label="备注"
          width="300">
      </el-table-column>
      <el-table-column
          prop="flag"
          label="状态"
          width="120">
        <template v-slot="s">
          <el-tag v-if="s.row.flag==1">未提交</el-tag>
          <el-tag v-if="s.row.flag==2">已提交</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          fixed="right"
          label="出库时间"
          width="100">
        <template slot-scope="scope">
          <el-button @click="toadd(scope.row.id)" type="text" size="small">添加工序</el-button>
          <el-button type="text" size="small">编辑</el-button>
          <el-button @click="toadd(scope.row.id)" type="text" size="small">提交工序</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="添加工序" :visible.sync="dialogFormVisible">
      <el-form :model="addprocess">
        <el-form-item label="工序名" :label-width="formLabelWidth">
          <el-input v-model="addprocess.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="编号条码" :label-width="formLabelWidth" >
          <el-input
              v-model="addprocess.bmnumber"
              autocomplete="off"
              :disabled="true">
          </el-input>
        </el-form-item>
        <el-form-item label="默认单价" :label-width="formLabelWidth">
          <el-input v-model="addprocess.price" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="当前状态" :label-width="formLabelWidth">
          <el-select v-model="addprocess.status" placeholder="请选择活动区域">
            <el-option label="正常" :value="0"></el-option>
            <el-option label="异常" :value="1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否外协工序" :label-width="formLabelWidth">
          <el-select v-model="addprocess.outsourcingProcess" placeholder="请选择活动区域">
            <el-option label="是" :value="0"></el-option>
            <el-option label="否" :value="1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否必检工序" :label-width="formLabelWidth">
          <el-select v-model="addprocess.checkProcess" placeholder="请选择活动区域">
            <el-option label="是" :value="0"></el-option>
            <el-option label="否" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="绑定班组" :label-width="formLabelWidth">
          <el-select v-model="addprocess.bid" placeholder="==请选择==">
            <el-option v-for="b in ban" :label="b.name" :value="b.id" :key="b.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="排序" :label-width="formLabelWidth">
          <el-input v-model="addprocess.sorts" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="备注" :label-width="formLabelWidth">
          <el-input v-model="addprocess.remark" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addProcess">确 定</el-button>
      </div>
    </el-dialog>


    <el-dialog title="添加工序" :visible.sync="dialogFormVisible">
      <el-form :model="addprocess">
        <el-form-item label="工序名" :label-width="formLabelWidth">
          <el-input v-model="addprocess.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="编号条码" :label-width="formLabelWidth" >
          <el-input v-model="addprocess.number" autocomplete="off" ></el-input>
        </el-form-item>
        <el-form-item label="默认单价" :label-width="formLabelWidth">
          <el-input v-model="addprocess.price" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="当前状态" :label-width="formLabelWidth">
          <el-select v-model="addprocess.status" placeholder="请选择活动区域">
            <el-option label="正常" :value="0"></el-option>
            <el-option label="异常" :value="1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否外协工序" :label-width="formLabelWidth">
          <el-select v-model="addprocess.outsourcingProcess" placeholder="请选择活动区域">
            <el-option label="是" :value="0"></el-option>
            <el-option label="否" :value="1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否必检工序" :label-width="formLabelWidth">
          <el-select v-model="addprocess.checkProcess" placeholder="请选择活动区域">
            <el-option label="是" :value="0"></el-option>
            <el-option label="否" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="绑定班组" :label-width="formLabelWidth">
          <el-select v-model="addprocess.bid" placeholder="==请选择==">
            <el-option v-for="b in ban" :label="b.name" :value="b.id" :key="b.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="排序" :label-width="formLabelWidth">
          <el-input v-model="addprocess.sort" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="备注" :label-width="formLabelWidth">
          <el-input v-model="addprocess.remark" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addProcess">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "GoodsView",
  data() {
    return {
      tableData:[],
      dialogFormVisible:false,
      addprocess:{
        bmnumber:'',
      },
      formLabelWidth:'120px',
      ban:[],

    }
  }, methods: {
    addProcess(){
      this.axios.post("/crop/addProcess",this.addprocess).then(()=>{
        this.$message.success("添加成功");
      })
    },
    getNumber(){
      this.axios.get("/crop/getNumber").then(res=>{
        this.addprocess.number=res;
      })
    },
    toadd(id){
      this.dialogFormVisible=true;
      this.addprocess.gid=id;
      this.getNumber();
    },
    getBan(){
      this.axios.post("/crop/getBid?type=6").then(res=>{
        this.ban=res.data.data;
      })
    },
    toruku(){
      this.$router.push("/putstash");
    },
    list(){
      this.axios.post("/crop/gList").then(r=>{
        this.tableData=r.data.data;
      })
    }
  }, created() {
    this.list();
    this.getBan();
  }
}
</script>

<style scoped>

</style>
